package com.musiklegal;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class BrowsePar extends DefaultHandler{

	String temp;
	private boolean in_genre = false;
	private boolean in_origin = false;
	private boolean in_artist = false;
	private Browse brow;

	
	public Browse getBrowse() {
		return brow;
	}
	BrowsePar()
	{
		brow = new Browse();
	}



	@Override
	public void startDocument() throws SAXException {
		
		
	}

	@Override
	public void endDocument() throws SAXException {
		
	}

	@Override
	public void startElement(String namespaceURI, String localName,
			String qName, Attributes atts) throws SAXException {
		 if (localName.equals("genre")) {
			    this.in_genre =true;
				
		 		}
		else if (localName.equals("origin")) {
				this.in_origin = true;
		}
		else if (localName.equals("artist")) {
			this.in_artist = true;
			brow.setId(atts.getValue("id")+"fachr1");
		}
		
	
	}
	
	@Override
	public void endElement(String namespaceURI, String localName, String qName)
			throws SAXException {
		
		if (localName.equals("genre")) {
			this.in_genre = false;
			brow.setGen("fachr1");
		}
		 else if (localName.equals("origin")) {
			 brow.setOri("fachr1");
				this.in_origin = false;
		}
		 else if (localName.equals("artist")) {
			 brow.setName("fachr1");
			 this.in_artist = false;
		}
		
	}
	
	/** Gets be called on the following structure: 
	 * <tag>characters</tag> */
	@Override
    public void characters(char ch[], int start, int length) {
		if(this.in_genre)
		{
			brow.setGen(new String(ch, start, length));
		}
		if(this.in_origin)
		{
			brow.setOri(new String(ch, start, length));
			
		}
		if(this.in_artist)
		{
			brow.setName(new String(ch, start, length));
			
		}
    }
}